package com.zhijian.warehouse.manage.entity.dto;

import com.zhijian.warehouse.manage.entity.po.User;
import com.zhijian.warehouse.manage.enums.RoleEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * @author HCG
 * @version 1.0
 * @date 2022/5/10
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserDto implements Serializable {
    private static final long serialVersionUID = 7579260560423182637L;

    /**
     * id
     */
    @ApiModelProperty(value = "id", hidden = true)
    private Long id;

    /**
     * 姓名
     */
    @ApiModelProperty("姓名")
    private String name;

    /**
     * 用户名
     */
    @ApiModelProperty("用户名")
    private String userName;

    /**
     * 手机号
     */
    @ApiModelProperty("手机号")
    private String phone;

    /**
     * 密码
     */
    @ApiModelProperty("密码")
    private String password;

    /**
     * 盐
     */
    @ApiModelProperty(value = "盐", hidden = true)
    private String salt;

    /**
     * 随机序号
     */
    private Integer sort;

    /**
     * 角色编码
     */
    private String roleCode;

    /**
     * 角色id数组
     */
    private List<Long> roleIds;

    /**
     * 角色枚举
     */
    private RoleEnum roleEnum;

    /**
     * 班级ID
     */
    private Long classId;

    /**
     * 分组ID
     */
    private Long groupId;

    /**
     * 登录类型  1 = 扫码登录
     */
    private Integer type;

    public static UserDto mergeFromPo(User user) {
        if (Objects.isNull(user)) {
            return null;
        }
        return UserDto.builder()
                .id(user.getId())
                .userName(user.getUserName())
                .name(user.getName())
                .phone(user.getPhone())
                .password(user.getPassword())
                .salt(user.getSalt())
                .build();
    }

}
